<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/*
    Class: MY_Loader
    Override load::view to fetch and print a PHPTAL template
*/
class MY_Loader extends CI_Loader {
    
    /*
        Variable: _ci
        Holds an instance of the CI class
    */
    private $_ci;
    
    
    /*
        Constructor:
        Calls parent constructor, and assigns an instance of the CI class
    */
    function __construct() {
        parent::__construct();
        $this->_ci =& get_instance();
    }
    
    /*
        Function: view
        Include PHPTAL and fetch the template file parse it
        
        Arguments:
        view    - String name of the view file to load (must exist in the
                  default view directory)
        data    - (optional) Array of data to send to the template
    */
    public function view($view, $data=array()) {
        // load the PHPTAL library and set the template file as the view
        $this->library('PHPTAL');
        
        $this->_ci->phptal->setTemplate($this->_ci_view_path.$view);
                
        // import the data into the template namespace
        foreach($data as $key => $value) {
            $this->_ci->phptal->set($key, $value);
        }
        
        // attempt to execute, and print, the template
        try {
            print $this->_ci->phptal->execute();
        }catch (Exception $e){
            show_error($e->getMessage());
        }
    }
}

?>